package reflect;

import reflect.annotations.AutoRunClass;
import reflect.annotations.AutoRunMethod;

import java.lang.reflect.Method;
import java.util.Scanner;

/**
 * 访问注解参数
 */
public class ReflectDemo11 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入一个类：");
        String className=scan.nextLine();
        System.out.println("请输入一个方法：");
        String methodName=scan.nextLine();


        Class cls=Class.forName(className);
        Method method = cls.getDeclaredMethod(methodName);
        if (method.isAnnotationPresent(AutoRunMethod.class)){
            AutoRunMethod autoRunMethod=method.getAnnotation(AutoRunMethod.class);
            int value=autoRunMethod.value();
            System.out.println(methodName+"方法注解参数是："+value);
        }else {
            System.out.println(methodName+"方法没有被标注");
        }
    }
}
